package com.sakura.mybatisplus.entity;

import com.baomidou.mybatisplus.annotation.*;
import com.sakura.mybatisplus.enums.StatusEnums;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.Date;

@Data
@NoArgsConstructor
//将user表映射到User这个类
@TableName(value = "user")
public class User {

    //映射到数据库中user表的主键id
    @TableId(value = "id", type = IdType.ASSIGN_ID)
    private Long id;

    //映射到数据库中user表中的name字段
    @TableField(value = "name")
    private String name;

    //映射到数据库中user表中的age字段
    @TableField(value = "age")
    private Integer age;

    //该字段为非表中字段
    @TableField(exist = false)
    private String gender;

    @TableField(fill = FieldFill.INSERT)
    private Date createTime;
    @TableField(fill = FieldFill.INSERT_UPDATE)
    private Date updateTime;

    @Version
    private Integer flag;


    @TableField(value = "status")
    private StatusEnums status;

    @TableLogic
    private Integer deleted;



    public User(String name, Integer age) {
        this.name = name;
        this.age = age;
    }

    public User(Long id, String name, Integer age, String gender, Date createTime, Date updateTime, Integer flag) {
        this.id = id;
        this.name = name;
        this.age = age;
        this.gender = gender;
        this.createTime = createTime;
        this.updateTime = updateTime;
        this.flag = flag;
    }

    @Override
    public String toString() {
        return "User{" +
                "id=" + id +
                ", name='" + name + '\'' +
                ", age=" + age +
                ", gender='" + gender + '\'' +
                ", createTime=" + createTime +
                ", updateTime=" + updateTime +
                ", flag=" + flag +
                ", status=" + status +
                '}';
    }
}
